﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace BluePortal.Medias.Core
{    
    public partial class EntitiesDataContext
    {
        public IQueryable<Video> Videos
        {
            get
            {
                return this.Medias.OfType<Video>();
            }
        }
        public IQueryable<Picture> Pictures
        {
            get
            {
                return this.Medias.OfType<Picture>();
            }
        }
    }

    public partial class Playlist
    {        
        public IEnumerable<Media> Videos
        {
            get 
            {
                if (!MediaPlaylists.IsDeferred)
                    return (IEnumerable<Media>)MediaPlaylists.Select(vpl => vpl.Media);
                else
                    return null;
            }
            set
            {
                throw new Exception("Not Serializable");
            }
        }
	
    }
    
    public partial class Channel
    {
        [System.Runtime.Serialization.DataMember]
        public int MemberCount
        {
            get;
            set;
        }
        public int VideoCount
        {
            get;
            set;
        }

        /// <summary>
        /// returns Video list from channel
        /// </summary>
        //[System.Runtime.Serialization.DataMember]
        public IEnumerable<Media> Videos
        {
            get
            {
                if (MediaChannels.IsDeferred)
                    return (IEnumerable<Media>) MediaChannels.Select(vc => vc.Media);
                else
                    return null;
            }
            set
            {
                throw new Exception("Not Serializable");
            }
        }
    }
}
